home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Softdisk Supreme
/
Softdisk Supreme.iso
/
pc
/
DSK Files
/
0-49
/
SD010b.dsk
/
ALL.BASE.CONVERTER.bas
next >
Wrap
BASIC Source File
|
2003-06-12
|
5KB
|
110 lines
5 REM SEND TO MAGAZETTE
10 GOTO 90
20 ON A GOTO 110,120,610,630,640,670,930,940,950,960
30 REM DELETE ALL LINES LISTED
40 REM IN THE ON 'A' GOTO
50 REM THEN DELETE LINE 10 THRU
60 REM THIS ONE, TO MAKE A GOOD
70 REM UTILITY PROGRAM
75 REM THIS PROGRAM DOES NOT
76 REM REFERENCE ANY REM WITH
77 REM A GOTO OR GOSUB, THEY
78 REM CAN ALL BE DELETED.
80 REM <CTRL-J>************************* * * * BASE CONVERTER * * TITLE PAGE * * * *************************
90 HOME
100 VTAB 2: HTAB 12: INVERSE : PRINT " BASE CONVERSION ": NORMAL
110 RESTORE
120 FOR K = 1 TO 10: READ MG$(K): NEXT K
130 IF P = 1 THEN 150
140 FOR K = 0 TO 2200: PRINT ;: NEXT
150 N$ = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
160 VTAB 4: CALL -958
170 M = LEN(N$)
180 VTAB 5: HTAB 10
190 PRINT "USE BASE TEN NOTATION"
200 VTAB 8
210 PRINT "CONVERT FROM"
220 PRINT "BASE ";
230 INPUT B1$
240 IF B1$ = CHR$(0) THEN 160
250 IF B1$ = "0" THEN 160
260 REM <CTRL-J>************************ * * * TEST BASE 1 * * * ************************
270 B1 = VAL(B1$)
280 IF B1 >1 AND B1 <37 THEN 320
290 VTAB 23: HTAB 2: INVERSE
300 PRINT "BASE 2 THROUGH 36 ONLY. SELECT AGAIN": NORMAL
310 GOTO 180
320 VTAB 8: HTAB 26
330 PRINT "CONVERTED TO"
340 HTAB 26: PRINT "BASE ";
350 INPUT B2$
360 IF B2$ = "0" THEN 160
370 IF B2$ = "" THEN 160
380 REM <CTRL-J>************************ * * * TEST BASE 2 * * * ************************
390 B2 = VAL(B2$)
400 IF B2 >1 THEN 440
410 VTAB 23
420 PRINT " BASE 2 THROUGH 36 ONLY. SELECT AGAIN. ";
430 GOTO 320
440 IF B2 >M THEN 410
445 REM <CTRL-J>*** INPUT NUMBER ***<CTRL-J>
450 VTAB 12: CALL -958
460 PRINT "VALUE IN BASE ";B1;" TO CONVERT";
470 INPUT S$
475 REM <CTRL-J>*** TEST INPUT ***<CTRL-J>
480 L = LEN(S$)
490 IF S$ = "0" THEN 450
500 IF S$ = "" THEN 450
510 FOR K = 1 TO L
520 IF MID$ (S$,K,1) = "." THEN VTAB 12: CALL -958: INVERSE : PRINT "WHOLE NUMBERS ONLY, NO DECIMALS": FOR J = 0 TO 3000: NEXT J: NORMAL : GOTO 450
530 NEXT K
540 Q = 0
550 FOR K = 1 TO L
560 FOR J = 1 TO B1
570 IF MID$ (S$,K,1) = MID$ (N$,J,1) THEN Q = Q +1
580 NEXT J: NEXT K
590 IF L >Q THEN GOSUB 980: GOTO 450
600 REM <CTRL-J>************************ * * * FIRST CONVERT * * TO BASE 10 * * * ************************
610 Y1 = Y1 +1
620 VTAB 19: HTAB 10
630 INVERSE : PRINT MG$(Y1): NORMAL
640 IF Y1 = 10 THEN Y1 = 0
650 IF L >7 THEN VTAB 23: INVERSE : PRINT " ANSWER MAYBE WRONG, NUMBER TOO LONG ";
660 NORMAL
670 FOR K = 1 TO 500 *L: NEXT K
675 REM <CTRL-J><CTRL-J>************************ * * * THE HEART OF THE * * PROGRAM * * THE NEXT 7 LINES * * * ************************
680 D = 0
690 FOR K = 1 TO L
700 FOR J = 1 TO B1
710 IF MID$ (N$,J,1) < > MID$ (S$,K,1) THEN 730
720 D = D + INT(((J -1) *(B1 ^(L -K)) +.5))
730 NEXT J
740 NEXT K
750 REM <CTRL-J>*********************** * * * CONVERT FOR OUTPUT * * * ***********************
760 A$ = " "
770 X = INT(((D/B2) - INT(D/B2)) *B2 +1.5)
780 A$ = MID$ (N$,X,1) +A$
790 D = INT(D/B2)
800 IF D >0 THEN 770
810 REM <CTRL-J>*********************** * * * PRINT RESULTS * * * ***********************
820 VTAB 15: HTAB 1: PRINT S$;" ";: INVERSE : PRINT " BASE ";: NORMAL : PRINT " ";B1;" = "
830 VTAB 17: HTAB 18: PRINT A$;" ";: INVERSE : PRINT " BASE ";: NORMAL : PRINT " ";B2
840 VTAB 19
850 PRINT "RETURN TO CONTINUE, ESCAPE TO CHANGE BASE, CONTROL-C TO QUIT.";: GET Q$
860 PRINT : PRINT
870 IF Q$ = CHR$(13) THEN 450
880 IF Q$ = CHR$(27) THEN P = 1: GOTO 90
890 IF Q$ = CHR$(3) THEN 920
900 GOTO 840
910 REM <CTRL-J>*********************** * * * THE END * * * ***********************
920 HOME : PRINT CHR$(4);"CATALOG": END
930 REM <CTRL-J>*********************** * * * DATA SECTION * * * ***********************
940 DATA " THAT'S A TOUGH ONE "," NOW LET ME THINK "," KEEP YOUR SHIRT ON "," WAIT, I'LL GET IT "
950 DATA " WHAT'S THE RUSH! "," HOW MANY MORE? "," ISN'T IT TIME TO EAT? "," I'M GETTING TIRED "
960 DATA " I KNOW- I'M SLOW "," IS THIS THE END? "
970 REM <CTRL-J>************************ * * * SUBROUTINE * * * ************************
980 VTAB 10: CALL -958
990 VTAB 12: HTAB 13
1000 INVERSE : PRINT " IMPROPER INPUT ": NORMAL
1010 FOR K = 1 TO 3000: NEXT : RETURN
1020 REM <CTRL-J>****************** * * * WRITTEN BY * * BOB SCOFIELD * * * ******************